/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_EXT_CHECKBOX_H_
#define TRI_EXT_CHECKBOX_H_

#include <iostream>
#include <vector>
#include <string>
#include <map>

//Include library header
#include "button.h"


namespace tri {
namespace ui {



//======================================================================

class extButtonGroup;

/**
 * Component class used for user interface
 */
class extCheckBox : public tri::ui::extButton {
	
	friend class extButtonGroup;
	
public:
	extCheckBox();
	virtual ~extCheckBox();
	
	/**
	 * Return the current checked state of this object.
	 * @return True os th object is checked. False if not.
	 */
	bool selected();
	
	/**
	 * Set checked state of this object.
	 * @param b True os th object is checked. False if not.
	 */
	void setSelected(bool b);
	
	/**
	 * Apply the current State
	 */
	virtual bool updateStyle();
	
	// called when the state of the check box changes
	sigslot::signal1<extCheckBox*,sigslot::multi_threaded_local> SELECTION_CHANGE;
	
private:
	// Checked state of object
	bool mChecked;
	extButtonGroup* mButtonGroup;
	
	
	class CheckBoxListener : public sigslot::has_slots<sigslot::multi_threaded_local>{
	public:
		CheckBoxListener(extCheckBox*);
		void onCheckBoxChange();
		
	private:
		extCheckBox* mBox;
	};
	
	CheckBoxListener* mCheckBoxListener; 
};

class extButtonGroup: public sigslot::has_slots<sigslot::multi_threaded_local>{
public:
	extButtonGroup();
	~extButtonGroup();
	
	void addCheckBoxToGroup(extCheckBox* b);
	void remove(extCheckBox* b);
	extCheckBox* removeFromGroup(int index);
	void setActive(int index);
	unsigned int size();
	int find(extCheckBox* b);
	void selectionChanged(extCheckBox* b);
	extCheckBox* getSelected();
	void removeAll();
private:
	std::vector<extCheckBox*> mButtonList;
};


}
}

#endif
